package com.example.zbh.dsliao.ui.activty;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;


/**
 *
 *
 * activity的基类
 * Created by zbh on 15/11/16.
 */
public abstract class BaseActivity extends Activity {
    protected InputMethodManager inputMethodManager;
    protected <T extends View > T findeView(int resd){
        return (T) findViewById(resd);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        initPresenter();
        setContentView(getLayOut());
        initView();
        initData();

    }

    protected void initPresenter() {
    }
    protected  abstract int getLayOut();//加载布局
    protected  abstract void initView();//初始化控件

    protected  abstract void initData();//初适化数据

    protected void hideSoftKeyboard() {
        if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (getCurrentFocus() != null)
                inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

}
